********************************************************************************
clear all
set more off
capture log close

********************************************************************************
** File paths
** Set the current directory to the same folder where the code is

global input "../input" 
global output "../output" 
global temp "../temp"

********************************************************************************
* Start log, save it into temp folder
log using "$temp/other_results", replace

********************************************************************************
** Watchers
********************************************************************************
use $temp/watchers, clear

drop if vLanguage  == "nl"

destring watchers, gen(vWatchersNum) force

gen vWatchersGroups = 1 if watchers == "<30" 
replace vWatchersGroups = 2 if vWatchersNum >= 30 &  vWatchersNum<50
replace vWatchersGroups = 3 if vWatchersNum >= 50 &  vWatchersNum<100
replace vWatchersGroups = 4 if vWatchersNum >= 100 & vWatchersNum!=.
tabulate vWatchersGroups

label define lWatchersGroups 1 "<30" 2 "30-49" 3 "50-99" 4 "100+", replace
label values vWatchersGroups lWatchersGroups 
tabulate vWatchersGroups

gen vLanguageGroups = 1 if vLanguage  == "de" | vLanguage == "it" | vLanguage == "fr"
replace vLanguageGroups = 2 if vLanguage  == "en" 
replace vLanguageGroups = 3 if vLanguage  == "es" 
label define lLanguageGroups 1 "Sample" 2 "English" 3 "Spanish" , replace
label values vLanguageGroups lLanguageGroups 
tabulate vLanguage vLanguageGr

tabulate vLanguageGr vWatchersGroups

graph bar , over(vWatchersGroups, label(labsize(large)) ) by(vLanguageGr, rows(1) note("") graphregion(fcolor(gs16) lcolor(gs16)) imargin(zero)) graphregion(fcolor(gs16)) scheme(s2mono) ytitle("Percent", size(large)) subtitle(, size(vlarge) fcolor(gs16) lcolor(gs16)) nofill ylabel(,labsize(large)) ysize(4) xsize(7) 
graph export $output/gWatchers.pdf, replace 

clear 

********************************************************************************
** Wikipedia official quality in English Wikipedia
********************************************************************************
use $temp/quality_wikipedia_offical, clear
egen tempGr = group(vPage)
replace vPage = ""
keep if tempGr <=5
replace vWPQuality = "Class B" if tempGr ==1
replace vWPQuality = "Good article" if tempGr ==2
replace vWPQuality = "Class A" if tempGr == 3
replace vWPQuality = "Featured list" if tempGr ==4 
replace vWPQuality = "Featured article" if tempGr ==5
drop temp*
drop vWPImportance

append using $temp/quality_wikipedia_offical
gen temp = 1 if vPage !=""

replace vWPQuality = "Class C" if vWPQuality == "C"
replace vWPQuality = "Not rated" if vWPQuality == "NA"

gen vOrder = 1 if vWPQuality == "Featured article"
replace vOrder = 2 if vWPQuality == "Featured list"
replace vOrder = 3 if vWPQuality == "Class A"
replace vOrder = 4 if vWPQuality == "Good article"
replace vOrder = 5 if vWPQuality == "Class B"
replace vOrder = 6 if vWPQuality == "Class C"
replace vOrder = 7 if vWPQuality == "Start"
replace vOrder = 8 if vWPQuality == "Stub"
replace vOrder = 9 if vWPQuality == "Not rated"

graph hbar (count) temp, over(vWPQ, sort(vOrder)) ytitle("Number of articles") graphregion(fcolor(gs16)) scheme(s2mono)
graph export $output/gEnglishQualityOfficial.pdf, replace 

** Importance
tabulate vWPImportance

********************************************************************************
** Do most editors add content or edit existing content
********************************************************************************
use $temp/temp_delete_add_edits, clear
gen vInd_BothAddDelete = (vEditAdd>0 & vEditDel>0)
gen vInd_AddLess100 = (vEditAdd<100)
gen vInd_AddMore1000 = (vEditAdd>1000)
keep date vPage vLanguage numericuserid vMonth vInd*
reshape long vInd_, i(date vPage vLanguage numericuserid vMonth) j(vEditType) string
rename vInd vIndicator

tabulate vEditType
replace vEditType = "Both add and delete" if vEditType == "BothAddDelete"
replace vEditType = "Add less than 100 char." if vEditType == "AddLess100"
replace vEditType = "Add more than 1000 char." if vEditType == "AddMore1000"

append using $temp/temp_minor_edits

tabulate vEditType
tabulate vEditType vIndicator, row
replace vIndicator = 100*vIndicator

tabulate vLanguage vIndicator

drop if vLanguage  == "nl"

** Without Dutch
graph hbar (mean) vInd, over(vEditType, label(labsize(medlarge))) blabel(bar, size(medlarge) format(%9.1f)) graphregion(fcolor(gs16)) scheme(s2mono) ytitle("Percent", size(medlarge)) ylabel(,labsize(medlarge))
graph export $output/gEditTypes.pdf, replace 

********************************************************************************
log close
clear
